// pages/zhangdan/zhangdan.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    array: ['全部','律师审核','充值', '购买套餐'],
    index:0,
    date: '2020-01',
    EventEmitter:[],
    navScrollLeft: 0,
    winWidth: 0,
    winHeight: 0, 
    currentTab:0,
    currentTab1:0,
    hidden: true,
    loadingData: false,
    p:0,
    listData: [],
    zhangdna:[],
    currentUrlIndex: 0,
    articles: [],
    hidden: true,
    loadingData: false,
    show:false,
  },
  bindDateChange: function(e) {
    var that = this;
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
    app.globalData.shijian = e.detail.value
  
    wx.request({
      url: app.globalData.url_l + 'api/member/zhangdan',
      method: 'post',
     data:{
        uid:app.globalData.uid,
     },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
         console.log(res)
         that.setData({
           zhangdna:res.data,
           zd_jl:res.data
         })
      }
    })
  },
    initData(id) {

    
  },
  loadData: function(tail, callback) {
    if(app.globalData.lishi ==undefined){
      app.globalData.lishi=0
    }
     var that = this,
      urlIndex = that.data.currentUrlIndex;
      console.log(urlIndex)
      if(urlIndex==0){
        urlIndex=1
      }
      var shul = 30*1*urlIndex*1
      that.data.p++;
      app.globalData.shul = 30*that.data.p
      console.log(app.globalData.shul)
      var that = this
      wx.request({
        url: app.globalData.url_l + 'api/member/zhangdan', //注意改成自己的服务器请求地址哦！
        method: 'POST',
        data:{
            uid:app.globalData.uid,
            state:app.globalData.yuanqu,
            time:app.globalData.shijian,
            shu:app.globalData.shul
        },
        method: 'post',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(res)
            wx.hideNavigationBarLoading();
            wx.stopPullDownRefresh();
            if(res.data.shi==""){
              that.setData({
                meiyougengdu: "display:block"
              })
            }
            var oldArticles =that.data.zhangdna,
            newArticles = tail ? oldArticles.concat(res.data) : res.data;
            app.globalData.cd_id1=newArticles.length
            var shi_dj = [];
            app.globalData.po=(urlIndex + 1) >= res.data.length? 0 : urlIndex + 1
            console.log(app.globalData.po)
            if(res.data.length==0){
              wx.showToast({
                title: "没有更多数据！",
                icon: 'none',
                duration: 2000
              })
            }
            that.setData({
              zhangdna: newArticles,
              currentUrlIndex: (urlIndex + 1) >= res.data.length ? 0 : urlIndex + 1,
            });
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
          if (callback) {
            callback();
          }
        },
      })
  // }
},

// /**
//  * 监听用户下拉动作
//  */
onPullDownRefresh: function() {
  var that = this
  console.log(app.globalData.shijian1)
  that.data.p = '0'
  wx.request({
    url: app.globalData.url_l + 'api/member/zhangdan', //注意改成自己的服务器请求地址哦！
        method: 'POST',
        data:{
            uid:app.globalData.uid,
            state:app.globalData.yuanqu,
            time:app.globalData.shijian1,
            shu:0
        },
    timeout:3000,
    method: 'post',
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function (res) {
      console.log(1211111)
      console.log(res)
         wx.hideNavigationBarLoading();
         wx.stopPullDownRefresh();
      app.globalData.huancun = res.data
        that.setData({
          zhangdna: res.data,
        })
    },
  })
  
  wx.showToast({
    title: "数据加载中...",
    icon: 'loading',
    duration: 2000
  })
  
},
// // /**
// //  * 页面上拉触底事件的处理函数
// //  */
onReachBottom: function() {
  console.log(1111)
  // if(app.globalData.state_lei==0||app.globalData.state_lei==1){

  // }else{
  console.info('onReachBottom');
  var hidden = this.data.hidden,
    loadingData = this.data.loadingData,
    that = this;
  if (hidden) {
    this.setData({
      hidden: false
    });
    //console.info(this.data.hidden);
  }
  if (loadingData) {
    return;
  }
  this.setData({
    loadingData: true
  });
  // 加载数据,模拟耗时操作
  wx.showToast({
    title: "数据加载中...",
    icon: 'loading',
    duration: 2000
  });

  setTimeout(function() {
    that.loadData(true, () => {
      that.setData({
        hidden: true,
        loadingData: false
      });
    });
     console.info('上拉数据加载完成.');
    }, 1000);
  // }
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     var that = this;
     app.globalData.shijian1 = ''
  //    if (app.globalData.userInfo) {
  //     this.setData({
  //         userInfo: app.globalData.userInfo,
  //         hasUserInfo: true
  //     })
  // } else if (this.data.canIUse) {
  //     app.userInfoReadyCallback = res => {
  //         this.setData({
  //             userInfo: res.userInfo,
  //             hasUserInfo: true
  //         })
  //     }
  // } else {
  //     wx.getUserInfo({
  //         success: res => {
  //             app.globalData.userInfo = res.userInfo
  //             this.setData({
  //                 userInfo: res.userInfo,
  //                 hasUserInfo: true
  //             })
  //         }
  //     })
  // }
  wx.getSystemInfo({
      success: (res) => {
          this.setData({
              pixelRatio: res.pixelRatio,
              windowHeight: res.windowHeight,
              windowWidth: res.windowWidth
          })
      },
  }) 
     app.globalData.shijian = '';
     app.globalData.yuanqu = '';
     wx.request({
      url: app.globalData.url_l + 'api/member/zhangdan',
      method: 'post',
     data:{
        state:app.globalData.yuanqu,
        uid:app.globalData.uid,
        shu:0
     },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
         console.log(res)
         that.setData({
           zhangdna:res.data,
           zd_jl:res.data
         })
      }
    })
  },
  bindPickerChange: function (e) {
    var that = this;
    this.setData({
      index: e.detail.value
    })
    app.globalData.yuanqu = e.detail.value
    console.log(app.globalData.yuanqu)
    if(app.globalData.yuanqu==0){
      app.globalData.shijian1 = ''
    }
    wx.request({
      url: app.globalData.url_l + 'api/member/zhangdan',
      method: 'post',
     data:{
        uid:app.globalData.uid,
        state:app.globalData.yuanqu,
        time:app.globalData.shijian1,
        shu:0
     },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
         console.log(res)
         that.setData({
           zhangdna:res.data,
           zd_jl:res.data
         })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },



  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})